//
//  FirstPushSecondViewController.m
//  UI10_作业
//
//  Created by dllo on 16/3/22.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "FirstPushSecondViewController.h"

@interface FirstPushSecondViewController ()<UITextFieldDelegate>

@end

@implementation FirstPushSecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor purpleColor];
    self.navigationItem.title = @"添加联系人";
    
    [self createAddContact];
}

- (void)createAddContact {
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 50, 50)];
    nameLabel.text = @"姓名";
    [self.view addSubview:nameLabel];
    self.nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(160, 100, 150, 50)];
    _nameTextField.placeholder = @"请输入姓名";
    _nameTextField.layer.borderWidth = 1;
    _nameTextField.layer.cornerRadius = 10;
    _nameTextField.layer.masksToBounds = YES;
    [self.view addSubview:_nameTextField];
    UILabel *phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 50, 50)];
    phoneLabel.text = @"电话";
    [self.view addSubview:phoneLabel];
    [phoneLabel release];
    self.phoneTextField = [[UITextField alloc] initWithFrame:CGRectMake(160, 200, 150, 50)];
    _phoneTextField.placeholder = @"请输入电话号码";
    _phoneTextField.layer.borderWidth = 1;
    _phoneTextField.layer.cornerRadius = 10;
    _phoneTextField.layer.masksToBounds = YES;
    [self.view addSubview:_phoneTextField];
    
    UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
    addButton.frame = CGRectMake(150, 300, 100, 50);
    [addButton setTitle:@"确定" forState:UIControlStateNormal];
    [addButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [addButton addTarget:self action:@selector(addButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addButton];
    addButton.backgroundColor = [UIColor blueColor];
}

- (void)addButtonAction:(UIButton *)addButton {
    [self.contactDelegate clickButtonWithName:_nameTextField.text phone:_phoneTextField.text];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
